home *** CD-ROM | disk | FTP | other *** search
/ TeX 1995 July / TeX CD-ROM July 1995 (Disc 1)(Walnut Creek)(1995).ISO / macros / mathematica / tex-mma.tar_z / tex-mma / psfig.tex < prev    next >
Text File  |  1990-05-24  |  10KB  |  391 lines

  1. % Psfig/TeX Release 1.2
  2. % dvips version
  3. %
  4. % All software, documentation, and related files in this distribution of
  5. % psfig/tex are Copyright 1987, 1988 Trevor J. Darrell
  6. %
  7. % Permission is granted for use and non-profit distribution of psfig/tex 
  8. % providing that this notice be clearly maintained, but the right to
  9. % distribute any portion of psfig/tex for profit or as part of any commercial
  10. % product is specifically reserved for the author.
  11. %
  12. % $Header: psfig.tex,v 1.9 88/01/08 17:42:01 trevor Exp $
  13. % $Source: $
  14. %
  15. % Thanks to Greg Hager (GDH) and Ned Batchelder for their contributions
  16. % to this project.
  17. %
  18. \catcode`\@=11\relax
  19. \newwrite\@unused
  20. \def\typeout#1{{\let\protect\string\immediate\write\@unused{#1}}}
  21. \typeout{psfig/tex 1.2-dvips}
  22.  
  23.  
  24. %% Here's how you define your figure path.  Should be set up with null
  25. %% default and a user useable definition.
  26.  
  27. \def\figurepath{./}
  28. \def\psfigurepath#1{\edef\figurepath{#1}}
  29.  
  30. %
  31. % @psdo control structure -- similar to Latex @for.
  32. % I redefined these with different names so that psfig can
  33. % be used with TeX as well as LaTeX, and so that it will not 
  34. % be vunerable to future changes in LaTeX's internal
  35. % control structure,
  36. %
  37. \def\@nnil{\@nil}
  38. \def\@empty{}
  39. \def\@psdonoop#1\@@#2#3{}
  40. \def\@psdo#1:=#2\do#3{\edef\@psdotmp{#2}\ifx\@psdotmp\@empty \else
  41.     \expandafter\@psdoloop#2,\@nil,\@nil\@@#1{#3}\fi}
  42. \def\@psdoloop#1,#2,#3\@@#4#5{\def#4{#1}\ifx #4\@nnil \else
  43.        #5\def#4{#2}\ifx #4\@nnil \else#5\@ipsdoloop #3\@@#4{#5}\fi\fi}
  44. \def\@ipsdoloop#1,#2\@@#3#4{\def#3{#1}\ifx #3\@nnil 
  45.        \let\@nextwhile=\@psdonoop \else
  46.       #4\relax\let\@nextwhile=\@ipsdoloop\fi\@nextwhile#2\@@#3{#4}}
  47. \def\@tpsdo#1:=#2\do#3{\xdef\@psdotmp{#2}\ifx\@psdotmp\@empty \else
  48.     \@tpsdoloop#2\@nil\@nil\@@#1{#3}\fi}
  49. \def\@tpsdoloop#1#2\@@#3#4{\def#3{#1}\ifx #3\@nnil 
  50.        \let\@nextwhile=\@psdonoop \else
  51.       #4\relax\let\@nextwhile=\@tpsdoloop\fi\@nextwhile#2\@@#3{#4}}
  52. %
  53. \def\psdraft{
  54.     \def\@psdraft{0}
  55.     %\typeout{draft level now is \@psdraft \space . }
  56. }
  57. \def\psfull{
  58.     \def\@psdraft{100}
  59.     %\typeout{draft level now is \@psdraft \space . }
  60. }
  61. \psfull
  62. \newif\if@prologfile
  63. \newif\if@postlogfile
  64. \newif\if@noisy
  65. \def\pssilent{
  66.     \@noisyfalse
  67. }
  68. \def\psnoisy{
  69.     \@noisytrue
  70. }
  71. \psnoisy
  72. %%% These are for the option list.
  73. %%% A specification of the form a = b maps to calling \@p@@sa{b}
  74. \newif\if@bbllx
  75. \newif\if@bblly
  76. \newif\if@bburx
  77. \newif\if@bbury
  78. \newif\if@height
  79. \newif\if@width
  80. \newif\if@rheight
  81. \newif\if@rwidth
  82. \newif\if@clip
  83. \newif\if@verbose
  84. \def\@p@@sclip#1{\@cliptrue}
  85.  
  86. %%% GDH 7/26/87 -- changed so that it first looks in the local directory,
  87. %%% then in a specified global directory for the ps file.
  88.  
  89. \def\@p@@sfile#1{\def\@p@sfile{null}%
  90.             \openin1=#1
  91.         \ifeof1\closein1%
  92.                \openin1=\figurepath#1
  93.             \ifeof1\typeout{Error, File #1 not found}
  94.             \else\closein1
  95.                 \edef\@p@sfile{\figurepath#1}%
  96.                         \fi%
  97.          \else\closein1%
  98.                \def\@p@sfile{#1}%
  99.          \fi}
  100. \def\@p@@sfigure#1{\def\@p@sfile{null}%
  101.             \openin1=#1
  102.         \ifeof1\closein1%
  103.                \openin1=\figurepath#1
  104.             \ifeof1\typeout{Error, File #1 not found}
  105.             \else\closein1
  106.                 \def\@p@sfile{\figurepath#1}%
  107.                         \fi%
  108.          \else\closein1%
  109.                \def\@p@sfile{#1}%
  110.          \fi}
  111.  
  112. \def\@p@@sbbllx#1{
  113.         %\typeout{bbllx is #1}
  114.         \@bbllxtrue
  115.         \dimen100=#1
  116.         \edef\@p@sbbllx{\number\dimen100}
  117. }
  118. \def\@p@@sbblly#1{
  119.         %\typeout{bblly is #1}
  120.         \@bbllytrue
  121.         \dimen100=#1
  122.         \edef\@p@sbblly{\number\dimen100}
  123. }
  124. \def\@p@@sbburx#1{
  125.         %\typeout{bburx is #1}
  126.         \@bburxtrue
  127.         \dimen100=#1
  128.         \edef\@p@sbburx{\number\dimen100}
  129. }
  130. \def\@p@@sbbury#1{
  131.         %\typeout{bbury is #1}
  132.         \@bburytrue
  133.         \dimen100=#1
  134.         \edef\@p@sbbury{\number\dimen100}
  135. }
  136. \def\@p@@sheight#1{
  137.         \@heighttrue
  138.         \dimen100=#1
  139.            \edef\@p@sheight{\number\dimen100}
  140.         %\typeout{Height is \@p@sheight}
  141. }
  142. \def\@p@@swidth#1{
  143.         %\typeout{Width is #1}
  144.         \@widthtrue
  145.         \dimen100=#1
  146.         \edef\@p@swidth{\number\dimen100}
  147. }
  148. \def\@p@@srheight#1{
  149.         %\typeout{Reserved height is #1}
  150.         \@rheighttrue
  151.         \dimen100=#1
  152.         \edef\@p@srheight{\number\dimen100}
  153. }
  154. \def\@p@@srwidth#1{
  155.         %\typeout{Reserved width is #1}
  156.         \@rwidthtrue
  157.         \dimen100=#1
  158.         \edef\@p@srwidth{\number\dimen100}
  159. }
  160. \def\@p@@ssilent#1{ 
  161.         \@verbosefalse
  162. }
  163. \def\@p@@sprolog#1{\@prologfiletrue\def\@prologfileval{#1}}
  164. \def\@p@@spostlog#1{\@postlogfiletrue\def\@postlogfileval{#1}}
  165. \def\@cs@name#1{\csname #1\endcsname}
  166. \def\@setparms#1=#2,{\@cs@name{@p@@s#1}{#2}}
  167. %
  168. % initialize the defaults (size the size of the figure)
  169. %
  170. \def\ps@init@parms{
  171.         \@bbllxfalse \@bbllyfalse
  172.         \@bburxfalse \@bburyfalse
  173.         \@heightfalse \@widthfalse
  174.         \@rheightfalse \@rwidthfalse
  175.         \def\@p@sbbllx{}\def\@p@sbblly{}
  176.         \def\@p@sbburx{}\def\@p@sbbury{}
  177.         \def\@p@sheight{}\def\@p@swidth{}
  178.         \def\@p@srheight{}\def\@p@srwidth{}
  179.         \def\@p@sfile{}
  180.         \def\@p@scost{10}
  181.         \def\@sc{}
  182.         \@prologfilefalse
  183.         \@postlogfilefalse
  184.         \@clipfalse
  185.         \if@noisy
  186.             \@verbosetrue
  187.         \else
  188.             \@verbosefalse
  189.         \fi
  190. }
  191. %
  192. % Go through the options setting things up.
  193. %
  194. \def\parse@ps@parms#1{
  195.          \@psdo\@psfiga:=#1\do
  196.            {\expandafter\@setparms\@psfiga,}}
  197. %
  198. % Compute bb height and width
  199. %
  200. \newif\ifno@bb
  201. \newif\ifnot@eof
  202. \newread\ps@stream
  203. \def\bb@missing{
  204.     \if@verbose{
  205.         \typeout{psfig: searching \@p@sfile \space  for bounding box}
  206.     }\fi
  207.     \openin\ps@stream=\@p@sfile
  208.     \no@bbtrue
  209.     \not@eoftrue
  210.     \catcode`\%=12
  211.     \loop
  212.         \read\ps@stream to \line@in
  213.         \global\toks200=\expandafter{\line@in}
  214.         \ifeof\ps@stream \not@eoffalse \fi
  215.         %\typeout{ looking at :: \the\toks200 }
  216.         \@bbtest{\toks200}
  217.         \if@bbmatch\not@eoffalse\expandafter\bb@cull\the\toks200\fi
  218.     \ifnot@eof \repeat
  219.     \catcode`\%=14
  220. }    
  221. \catcode`\%=12
  222. \newif\if@bbmatch
  223. \def\@bbtest#1{\expandafter\@a@\the#1%%BoundingBox:\@bbtest\@a@}
  224. \long\def\@a@#1%%BoundingBox:#2#3\@a@{\ifx\@bbtest#2\@bbmatchfalse\else\@bbmatchtrue\fi}
  225. \long\def\bb@cull#1 #2 #3 #4 #5 {
  226.     \dimen100=#2 bp\edef\@p@sbbllx{\number\dimen100}
  227.     \dimen100=#3 bp\edef\@p@sbblly{\number\dimen100}
  228.     \dimen100=#4 bp\edef\@p@sbburx{\number\dimen100}
  229.     \dimen100=#5 bp\edef\@p@sbbury{\number\dimen100}
  230.     \no@bbfalse
  231. }
  232. \catcode`\%=14
  233. %
  234. \def\compute@bb{
  235.         \no@bbfalse
  236.         \if@bbllx \else \no@bbtrue \fi
  237.         \if@bblly \else \no@bbtrue \fi
  238.         \if@bburx \else \no@bbtrue \fi
  239.         \if@bbury \else \no@bbtrue \fi
  240.         \ifno@bb \bb@missing \fi
  241.         \ifno@bb \typeout{FATAL ERROR: no bb supplied or found}
  242.             \no-bb-error
  243.         \fi
  244.         %
  245.         \count203=\@p@sbburx
  246.         \count204=\@p@sbbury
  247.         \advance\count203 by -\@p@sbbllx
  248.         \advance\count204 by -\@p@sbblly
  249.         \edef\@bbw{\number\count203}
  250.         \edef\@bbh{\number\count204}
  251.         %\typeout{ bbh = \@bbh, bbw = \@bbw }
  252. }
  253. %
  254. % \in@hundreds performs #1 * (#2 / #3) correct to the hundreds,
  255. %    then leaves the result in @result
  256. %
  257. \def\in@hundreds#1#2#3{\count240=#2 \count241=#3
  258.              \count100=\count240    % 100 is first digit #2/#3
  259.              \divide\count100 by \count241
  260.              \count101=\count100
  261.              \multiply\count101 by \count241
  262.              \advance\count240 by -\count101
  263.              \multiply\count240 by 10
  264.              \count101=\count240    %101 is second digit of #2/#3
  265.              \divide\count101 by \count241
  266.              \count102=\count101
  267.              \multiply\count102 by \count241
  268.              \advance\count240 by -\count102
  269.              \multiply\count240 by 10
  270.              \count102=\count240    % 102 is the third digit
  271.              \divide\count102 by \count241
  272.              \count200=#1\count205=0
  273.              \count201=\count200
  274.             \multiply\count201 by \count100
  275.              \advance\count205 by \count201
  276.              \count201=\count200
  277.             \divide\count201 by 10
  278.             \multiply\count201 by \count101
  279.             \advance\count205 by \count201
  280.             %
  281.              \count201=\count200
  282.             \divide\count201 by 100
  283.             \multiply\count201 by \count102
  284.             \advance\count205 by \count201
  285.             %
  286.              \edef\@result{\number\count205}
  287. }
  288. \def\compute@wfromh{
  289.         % computing : width = height * (bbw / bbh)
  290.         \in@hundreds{\@p@sheight}{\@bbw}{\@bbh}
  291.         %\typeout{ \@p@sheight * \@bbw / \@bbh, = \@result }
  292.         \edef\@p@swidth{\@result}
  293.         %\typeout{w from h: width is \@p@swidth}
  294. }
  295. \def\compute@hfromw{
  296.         % computing : height = width * (bbh / bbw)
  297.         \in@hundreds{\@p@swidth}{\@bbh}{\@bbw}
  298.         %\typeout{ \@p@swidth * \@bbh / \@bbw = \@result }
  299.         \edef\@p@sheight{\@result}
  300.         %\typeout{h from w : height is \@p@sheight}
  301. }
  302. \def\compute@handw{
  303.         \if@height 
  304.             \if@width
  305.             \else
  306.                 \compute@wfromh
  307.             \fi
  308.         \else 
  309.             \if@width
  310.                 \compute@hfromw
  311.             \else
  312.                 \edef\@p@sheight{\@bbh}
  313.                 \edef\@p@swidth{\@bbw}
  314.             \fi
  315.         \fi
  316. }
  317. \def\compute@resv{
  318.         \if@rheight \else \edef\@p@srheight{\@p@sheight} \fi
  319.         \if@rwidth \else \edef\@p@srwidth{\@p@swidth} \fi
  320. }
  321. %        
  322. % Compute any missing values
  323. \def\compute@sizes{
  324.     \compute@bb
  325.     \compute@handw
  326.     \compute@resv
  327. }
  328. %
  329. % \psfig
  330. % usage : \psfig{file=, height=, width=, bbllx=, bblly=, bburx=, bbury=,
  331. %            rheight=, rwidth=, clip=}
  332. %
  333. % "clip=" is a switch and takes no value, but the `=' must be present.
  334. \def\psfig#1{\vbox {
  335.     % do a zero width hard space so that a single
  336.     % \psfig in a centering enviornment will behave nicely
  337.     %{\setbox0=\hbox{\ }\ \hskip-\wd0}
  338.     %
  339.     \ps@init@parms
  340.     \parse@ps@parms{#1}
  341.     \compute@sizes
  342.     %
  343.     \ifnum\@p@scost<\@psdraft{
  344.         \if@verbose{
  345.             \typeout{psfig: including \@p@sfile \space }
  346.         }\fi
  347.         %
  348.         \special{ps::[begin]     \@p@swidth \space \@p@sheight \space
  349.                 \@p@sbbllx \space \@p@sbblly \space
  350.                 \@p@sbburx \space \@p@sbbury \space
  351.                 startTexFig \space }
  352.         \if@clip{
  353.             \if@verbose{
  354.                 \typeout{(clip)}
  355.             }\fi
  356.             \special{ps:: doclip \space }
  357.         }\fi
  358.         \if@prologfile
  359.             \special{ps: plotfile \@prologfileval \space } \fi
  360.         \special{ps: plotfile \@p@sfile \space }
  361.         \if@postlogfile
  362.             \special{ps: plotfile \@postlogfileval \space } \fi
  363.         \special{ps::[end] endTexFig \space }
  364.         % Create the vbox to reserve the space for the figure
  365.         \vbox to \@p@srheight true sp{
  366.             \hbox to \@p@srwidth true sp{
  367.                 \hss
  368.             }
  369.         \vss
  370.         }
  371.     }\else{
  372.         % draft figure, just reserve the space and print the
  373.         % path name.
  374.         \vbox to \@p@srheight true sp{
  375.         \vss
  376.             \hbox to \@p@srwidth true sp{
  377.                 \hss
  378.                 \if@verbose{
  379.                     \@p@sfile
  380.                 }\fi
  381.                 \hss
  382.             }
  383.         \vss
  384.         }
  385.     }\fi
  386. }}
  387. \def\psglobal{\typeout{psfig: PSGLOBAL is OBSOLETE; use psprint -m instead}}
  388. \catcode`\@=12\relax
  389.  
  390.